﻿namespace Leetcode.N0821;

public class Solution
{
    public int[] ShortestToChar(string s, char c)
    {
        var result = new int[s.Length];
        result[s.Length - 1] = s[s.Length - 1] == c ? 0 : 2 * s.Length;

        for (int i = s.Length - 2; i >= 0; i--)
        {
            result[i] = s[i] == c ? 0 : result[i + 1] + 1;
        }

        for (int i = 1; i < s.Length; i++)
        {
            result[i] = Math.Min(result[i - 1] + 1, result[i]);
        }

        return result;

    }
}
